<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%@include file="/assets/publicjsp.jsp"%>
    <title>我的用户列表</title>

</head>
<body>
<%@include file="../assets/header.jsp"%>

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <%@include file="../assets/side.jsp"%>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">我的关注列表</h2>
            </div>
        </div>
        <section class="no-padding-bottom">

            <div class="list-group myList">
                <ul>
                    <c:forEach items="${pageData.data}" var="userFocus">
                        <li class="list-group-item">
                            <c:choose>
                                <c:when test="${userFocus.realName != null || userFocus.realName != ''}">
                                    <a href="/user/userDetail?flag=1&id=${userFocus.userId}">${userFocus.realName}</a>
                                </c:when>
                                <c:otherwise>
                                    <a href="/user/userDetail?flag=1&id=${userFocus.userId}">${userFocus.username}</a>
                                </c:otherwise>
                            </c:choose>
                            <div style="float: right" class="text-right">
                                <input type="button" class="btn btn-danger" onclick="unFocus(${userFocus.userId})" value="取消关注">
                            </div>
                        </li>
                    </c:forEach>
                </ul>
                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a href="${pageContext.request.contextPath}/user/findFocus?currPage=${pageData.currPage==1 ? pageData.currPage : pageData.currPage - 1}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="${pageData.begin}" end="${pageData.end}" step="1" var="p">
                            <c:if test="${p == pageData.currPage}">
                                <li><a class="nav-active" href="${pageContext.request.contextPath}/user/findFocus?currPage=${p}">${p}</a></li>
                            </c:if>
                            <c:if test="${p != pageData.currPage}">
                                <li><a href="${pageContext.request.contextPath}/user/findFocus?currPage=${p}">${p}</a></li>
                            </c:if>
                        </c:forEach>
                        <li>
                            <a href="${pageContext.request.contextPath}/user/findFocus?currPage=${pageData.currPage==pageData.totalPage ? pageData.currPage : pageData.currPage + 1}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </section>

        <%@include file="../assets/footer.jsp"%>
    </div>
</div>
<script>
    function unFocus(userId) {
        $.post("/user/focus?userId=" + userId,function (res) {
            if(res == 0){
                layer.msg("取关成功！", {
                    time: 1000,
                    end: function(){
                        if(${pageData.currPage != 1 && pageData.totalCount <= pageData.pageSize+1}){
                            location.href='${pageContext.request.contextPath}/user/findFocus?currPage=1';
                        }else{
                            window.location.reload();
                        }
                    }
                });
            }
        });
    }

</script>
</body>
</html>